﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Innova.Microfinanzas.Windows.Common.Views
{
    public partial class UserChangePassword : Form
    {
        public UserChangePassword()
        {
            InitializeComponent();
        }

        public static List<string> ChangePassword(string oldPassword = "")
        {
            List<string> newPasswords = new List<string>();
            UserChangePassword form = new UserChangePassword();
            form.OldPassword = oldPassword;
            DialogResult result = form.ShowDialog();
            if (result == DialogResult.OK)
            {
                newPasswords = form.NewPasswordData;
            }
            return newPasswords;
        }

        public string OldPassword
        {
            set
            {
                fieldOldPassword.Text = value;
            }
        }

        public List<string> NewPasswordData
        {
            get
            {
                List<string> colData = new List<string>();
                colData.Add(fieldOldPassword.Text.Trim());
                colData.Add(fieldPassword.Text.Trim());
                return colData;
            }
        }

        private void tsSaveButtonToolStrip_Click(object sender, EventArgs e)
        {
            StringBuilder message = new StringBuilder();
            bool vResult = true;
            bool isPasswordFill = true;

            if (string.IsNullOrEmpty(fieldPassword.Text.Trim()))
            {
                isPasswordFill = false;
                vResult = false;
                message.AppendLine("Debe ingresar una contraseña.");
            }

            if (string.IsNullOrEmpty(fieldPasswordConfirm.Text.Trim()))
            {
                isPasswordFill = false;
                vResult = false;
                message.AppendLine("Debe ingresar la confirmación de la contraseña.");
            }

            if (isPasswordFill)
            {
                if (fieldPassword.Text.Trim() != fieldPasswordConfirm.Text.Trim())
                {
                    vResult = false;
                    message.AppendLine("Las contraseñas ingresadas son diferentes, por favor vuelva a ingresar ambas.");
                }
            }

            if (vResult)
            {
                DialogResult = DialogResult.OK;
                Close();
            }
            else
            {
                MessageBox.Show(message.ToString(), "Cambio de contraseña", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        private void tsCancelButtonToolStrip_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Abort;
            Close();
        }
    }
}
